//
//  TPPayCell.m
//  Tripvi
//
//  Created by xiaowuxiaowu on 2017/5/17.
//  Copyright © 2017年 xiaowuxiaowu. All rights reserved.
//

#import "TPPayCell.h"
@interface TPPayCell()
@property (nonatomic,strong)UIButton *wxButton;
@property (nonatomic,strong)UIButton *aliButton;
@end

@implementation TPPayCell

-(void)willMoveToSuperview:(UIView *)newSuperview{
    [super willMoveToSuperview:newSuperview];
    
    self.title_label.textColor = TPAllBackgroundColor;
    
    [self.title_label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self);
        make.left.mas_equalTo(20.0f);
        make.top.bottom.mas_equalTo(0.0f);
        
    }];
    
    [self.detail_label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self);
        make.left.mas_equalTo(self.title_label.mas_right).offset(10.0);
         make.top.bottom.mas_equalTo(0.0f);
    }];
    
    [self.wxButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.detail_label.mas_left).offset(-18.0);
        make.centerY.mas_equalTo(self.title_label.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(90.0, 30.0));
    }];
    
    [self.aliButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.wxButton.mas_right);
        make.centerY.mas_equalTo(self.title_label.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(90.0, 30.0));
    }];
    
}
-(void)setIsWechatPay:(BOOL)isWechatPay{
    _isWechatPay = isWechatPay;
   
        self.wxButton.selected = isWechatPay;
       self.aliButton.selected = !isWechatPay;
   
}
-(void)layoutSubviews{
    [super layoutSubviews];
    self.separatorInset = UIEdgeInsetsMake(0, 20.0f, 0, 20.0);
    self.detail_label.hidden = NO;
    self.wxButton.hidden = self.aliButton.hidden = YES;
    switch (self.indexPath.row) {
        case 3:
        {
            self.detail_label.hidden = YES;
            self.wxButton.hidden = self.aliButton.hidden = NO;
        }
            break;
            
        default:
            break;
    }
    
}

-(UIButton *)wxButton{
 
    if(!_wxButton){
    
        
        _wxButton = [UIButton buttonWithFrame:CGRectZero title:@"微信" font:fontSystemOfSize(15) color:TPBlack_999999];
        [_wxButton setImage:ImageNamed(@"Choose_normal_icon") forState:UIControlStateNormal];
        [_wxButton setImage:ImageNamed(@"Choose_select_icon") forState:UIControlStateSelected];
        [_wxButton setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 8.0)];
        _wxButton.tag = 111;
        [_wxButton addTouchUpInsideTarget:self action:@selector(actionButton:)];
        _wxButton.userInteractionEnabled = YES;
        [self.contentView addSubview:_wxButton];
        
    }
    return _wxButton;
}
-(UIButton *)aliButton{
    
    if(!_aliButton){
        
        _aliButton = [UIButton buttonWithFrame:CGRectZero title:@"支付宝" font:fontSystemOfSize(15) color:TPBlack_999999];
        [_aliButton setImage:ImageNamed(@"Choose_select_icon") forState:UIControlStateSelected];
        [_aliButton setImage:ImageNamed(@"Choose_normal_icon") forState:UIControlStateNormal];
        [_aliButton setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 8.0)];
        _aliButton.userInteractionEnabled = YES;
        _aliButton.tag = 222;
        [_aliButton addTouchUpInsideTarget:self action:@selector(actionButton:)];
        [self.contentView addSubview:_aliButton];
        
    }
    return _aliButton;
}

-(void)actionButton:(UIButton *)sender{
    
    sender.selected = YES;
    UIButton *button = [self.contentView viewWithTag:sender.tag==111 ? 222:111];
    button.selected = NO;
    
    if(self.actionBlock){
        self.actionBlock(sender.tag == 111);
    }
}
@end
